package com.sunop.userservice.task;



import com.sunop.userservice.model.EmailMessage;
import com.sunop.userservice.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class EmailConsumer {
    @Autowired
    private UserService userService;
    
    @RabbitListener(queues = "email.queue")
    public void processEmailMessage(EmailMessage message) {
        try {
            userService.sendVerificationEmail(message.getToEmail(), message.getVerificationCode());
        } catch (Exception e) {
            log.error("邮件发送失败: " + e.getMessage());
        }
    }
}